package com.stp.rabbitmq.config;

import com.stp.rabbitmq.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由交换机 点对点
 * 第一个是队列名
 * 第二个 durable="true" 持久化 rabbitmq重启的时候不需要创建新的队列
 * 第三个exclusive  表示该消息队列是否只在当前connection生效,默认是false
 * 第四个auto-delete 表示消息队列没有在使用时将被自动删除 默认是false
 */
@Configuration
public class DirectConfig {
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(QueueConstant.DIRECT_EXCHANGE);
    }

    @Bean
    public Queue directQueueOne(){
        return new Queue(QueueConstant.DIRECT_QUEUE_ONE,true);
    }

    @Bean
    public Queue directQueueTWO(){
        return new Queue(QueueConstant.DIRECT_QUEUE_TWO,true);
    }

    @Bean
    public Queue directQueueCommon(){
        return new Queue(QueueConstant.COMMON_QUEUE,true);
    }

    @Bean
    public Binding bindingDirect1() {
        return BindingBuilder.bind(directQueueOne()).to(directExchange()).with("queue.red");
    }

    @Bean
    public Binding bindingDirect2() {
        return BindingBuilder.bind(directQueueTWO()).to(directExchange()).with("queue.blue");
    }

    @Bean
    public Binding bindingDirect3() {
        return BindingBuilder.bind(directQueueCommon()).to(directExchange()).with("queue.common");
    }
}
